﻿namespace SourceCodeRepository.Model.Validators
{
    using Entitites;
    using Infra.Validation;
    using ValidationRules.CodeSnippetRules;

    /// <summary>
    /// Validator for a Code Snippet entity.
    /// </summary>
    public class CodeSnippetValidator : IValidator<CodeSnippet>
    {
        /// <summary>
        /// Gets the starting validation rule.
        /// </summary>
        /// <value>The starting rule.</value>
        private ValidationRuleFor<CodeSnippet> StartingRule
        {
            get { return new ContributorEmptyValidationRule(); }
        }

        /// <summary>
        /// Validates the specified snippet.
        /// </summary>
        /// <param name="snippet">The snippet.</param>
        /// <returns></returns>
        public ValidationResult Validate(CodeSnippet snippet)
        {
            var result = new ValidationResult();

            if (snippet != null)
            {
                result = new ValidationEngineFor<CodeSnippet>(this.StartingRule, result).Validate(snippet);
            }
            else
            {
                result.AddError("The snippet data is invalid.");
            }
            return result;
        }
    }
}
